********************************************************************************
* Project: Measuring party system nationalisation
*  Author: Kazuma Mizukoshi
*    Date: 13 August 2020
********************************************************************************

********************************************************************************
* TASK-1: Import datasets
* TASK-2: Create time variables
* TASK-3: Estimate linear mixed models for Brazil
* TASK-4: Estimate linear mixed models for Ecuador
********************************************************************************

********************************************************************************
* TASK-1: Import datasets
********************************************************************************
use "Brazil.xlsx"
use "Ecuador.xlsx"
replace PartyVoteShare = PartyVoteShare+.0001 if PartyVoteShare == 0

********************************************************************************
* TASK-2: Create time variables
********************************************************************************
	gen T1_2=T1^2
	gen T1_3=T1^3

********************************************************************************
* TASK-3: Estimate linear mixed models for Brazil
********************************************************************************
*Model 1
	xtmixed PartyVoteShare T1 T1_2 T1_3, mle var
    est store m1
    estat ic

* Model 2
	xtmixed PartyVoteShare T1 T1_2 T1_3 ||PartyName:T1, mle var cov(unstr) 
    est store m2
    estat ic
	
* Model 3
	xtmixed PartyVoteShare T1 T1_2 T1_3 ||PartyName:T1  ||ConstituencyName:T1, mle var cov(unstr) 
    est store m3
    estat ic
	
********************************************************************************
* TASK-4: Estimate linear mixed models for Ecuador
********************************************************************************
*Model 1
	xtmixed PartyVoteShare T1 T1_2 T1_3, mle var
    est store m1
    estat ic

* Model 2
	xtmixed PartyVoteShare T1 T1_2 T1_3 ||PartyName:T1, mle var cov(unstr) 
    est store m2
    estat ic
	
* Model 3
	xtmixed PartyVoteShare T1 T1_2 T1_3 ||PartyName:T1  ||ConstituencyName:T1, mle var cov(unstr) 
    est store m3
    estat ic
	